/*
 * @Author: your name
 * @Date: 2021-09-01 16:37:05
 * @LastEditTime: 2021-09-07 14:34:53
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \bigdate\src\ntils\helper.ts
 */
import { IconArr } from '../router/type'

const modules = import.meta.globEager('../assets/svg/*.svg')
export interface Iterator{
       name:String,
       value:String
}
// 获取全部图标
export const filterSvg = function ():Array<IconArr> {
    let Reault:Array<IconArr> = []
    Object.keys(modules).forEach((key) => {
        let iconPath = key.replace(/([.]+)\/(assets)\/(svg)\//g, '')
        let obj:IconArr = {
            name: iconPath.replace('.svg', ''),
        }
        Reault.push(obj)
    })    
    return Reault
}

// 格式化数据
export const jsonToObj = function (data):Promise<{}> {
    let datas = data ?? []
    let objs:Array<Iterator> = [] 
    return new Promise((reslove, inject) => {
        if (datas == [] || typeof datas != 'object') {
            inject(datas) 
        } else {
            for (const item in datas) {
                objs.push({
                    name: item,
                    value: data[item],
                })
            } 
            reslove(objs) 
        }
    })
}   
